package com.codedancer.campus.manager.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.codedancer.campus.manager.service.IConfessionalWallExamineRecordService;
import com.codedancer.campus.manager.service.IConfessionalWallExamineRecordService;
import com.codedancer.campus.manager.service.bo.confessionalWall.ConfessionalWallExamineRecordPageSearchBo;
import com.codedancer.campus.manager.service.bo.confessionalWall.ConfessionalWallExamineRecordPageSearchBo;
import com.codedancer.campus.manager.service.vo.confessionalWall.ConfessionalWallExamineRecordVo;
import com.codedancer.campus.mapper.ConfessionalWallExamineRecordMapper;
import com.codedancer.campus.mapper.ConfessionalWallExamineRecordMapper;
import com.codedancer.campus.po.ConfessionalWallExamineRecord;
import com.codedancer.campus.qo.confessionalWall.ConfessionalWallExamineRecordPageSearchQo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;

@Service
@Transactional(rollbackFor = Exception.class)
public class ConfessionalWallExamineRecordServiceImpl implements IConfessionalWallExamineRecordService {

    @Autowired
    private ConfessionalWallExamineRecordMapper confessionalWallExamineRecordMapper;

    /**
     * 分页查询商品审核记录
     *
     * @param confessionalWallExamineRecordPageSearchBo
     * @return
     */
    @Override
    public IPage<ConfessionalWallExamineRecordVo> page(
        ConfessionalWallExamineRecordPageSearchBo confessionalWallExamineRecordPageSearchBo) {
        ConfessionalWallExamineRecordPageSearchQo confessionalWallExamineRecordPageSearchQo = BeanUtil
            .copyProperties(confessionalWallExamineRecordPageSearchBo,
                ConfessionalWallExamineRecordPageSearchQo.class);
        IPage<ConfessionalWallExamineRecord> confessionalWallExamineRecordIPage = confessionalWallExamineRecordMapper
            .page(new Page<ConfessionalWallExamineRecord>(confessionalWallExamineRecordPageSearchBo.getPage(),
                    confessionalWallExamineRecordPageSearchBo.getSize()), confessionalWallExamineRecordPageSearchQo);
        List<ConfessionalWallExamineRecordVo> confessionalWallExamineRecordVos;
        IPage<ConfessionalWallExamineRecordVo> confessionalWallExamineRecordVoIPage = new Page<>();
        confessionalWallExamineRecordVos = confessionalWallExamineRecordIPage.getRecords().stream()
            .map(confessionalWallExamineRecord -> {
                ConfessionalWallExamineRecordVo confessionalWallExamineRecordVo = BeanUtil
                    .copyProperties(confessionalWallExamineRecord, ConfessionalWallExamineRecordVo.class);
                confessionalWallExamineRecordVo
                    .setExamineAdminName(confessionalWallExamineRecord.getAdmin().getLoginName());
                return confessionalWallExamineRecordVo;
            }).collect(Collectors.toList());
        confessionalWallExamineRecordVoIPage.setRecords(confessionalWallExamineRecordVos);
        confessionalWallExamineRecordVoIPage.setTotal(confessionalWallExamineRecordIPage.getTotal());
        return confessionalWallExamineRecordVoIPage;
    }
}
